﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

class BillDAL
{
    DataAccess acc = new DataAccess();
    internal DataTable getAllBill()
    {
        return acc.executeSelect("getAllBill");
    }

    internal DataTable getBillByID(int id)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("@Bi_ID", SqlDbType.Int);
        paraList[0].Value = id;
        return acc.executeSelect("getBillById", paraList);
    }

    internal bool updateBillStatus(int Bi_ID, string Status)
    {
        SqlParameter[] paraList = new SqlParameter[2];
        paraList[0] = new SqlParameter("@Bi_ID", SqlDbType.Int);
        paraList[0].Value = Bi_ID;
        paraList[1] = new SqlParameter("@Bi_Status", SqlDbType.NVarChar, 50);
        paraList[1].Value = Status;
        int check = acc.executeModifier("updateBillStatus", paraList);
        if (check > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    internal DataTable getBillDoneStatus(string dateCompleted)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("@Bi_DateCompleted", SqlDbType.NVarChar,200);
        paraList[0].Value = dateCompleted;
        return acc.executeSelect("getBillByDoneStatus", paraList);
    }

    internal DataTable getBillNotStatus(string dateCompleted)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("@Bi_DateCompleted", SqlDbType.NVarChar,200);
        paraList[0].Value = dateCompleted;
        return acc.executeSelect("getBillByNotStatus", paraList);
    }

    internal DataTable getBillByDateAndStatus(string dateCompleted)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("@Bi_DateCompleted", SqlDbType.NVarChar, 200);
        paraList[0].Value = dateCompleted;
        return acc.executeSelect("getBillByDateAndStatus", paraList);
    }

    internal bool insertBill(float totalAmount, string address, string date, string dateC, string memID, string mess, string status)
    {
        SqlParameter[] paraList = new SqlParameter[7];
        paraList[0] = new SqlParameter("@Bi_TotalAmount", SqlDbType.Float);
        paraList[0].Value = totalAmount;
        paraList[1] = new SqlParameter("@Bi_Address", SqlDbType.NVarChar, 4000);
        paraList[1].Value = address;
        paraList[2] = new SqlParameter("@Bi_Date", SqlDbType.NVarChar, 200);
        paraList[2].Value = date;
        paraList[3] = new SqlParameter("@Bi_DateCompleted", SqlDbType.NVarChar, 200);
        paraList[3].Value = dateC;
        paraList[4] = new SqlParameter("@M_ID", SqlDbType.NVarChar, 50);
        paraList[4].Value = memID;
        paraList[5] = new SqlParameter("@Bi_Messages", SqlDbType.NVarChar, 4000);
        paraList[5].Value = mess;
        paraList[6] = new SqlParameter("@Bi_Status", SqlDbType.NVarChar, 50);
        paraList[6].Value = status;
        int check = acc.executeModifier("InsertBill",paraList);
        if (check > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    internal DataTable getBillByManyFiels(float totalAmount, string date, string dateC, string address, string memID)
    {
        SqlParameter[] paraList = new SqlParameter[5];
        paraList[0] = new SqlParameter("@Bi_TotalAmount", SqlDbType.Float);
        paraList[0].Value = totalAmount;
        paraList[1] = new SqlParameter("@Bi_Date", SqlDbType.NVarChar, 4000);
        paraList[1].Value = date;
        paraList[2] = new SqlParameter("@Bi_DateCompleted", SqlDbType.NVarChar, 200);
        paraList[2].Value = dateC;
        paraList[3] = new SqlParameter("@Bi_Address", SqlDbType.NVarChar, 200);
        paraList[3].Value = address;
        paraList[4] = new SqlParameter("@M_ID", SqlDbType.NVarChar, 50);
        paraList[4].Value = memID;

        return acc.executeSelect("getBillByManyFiels", paraList);
        
    }
}
